﻿@model Web.BaseModel
@{
    ViewBag.Title = "Default";
}

<html>
<head>
    <title>顾客列表</title>
    <script src="~/js/jquery-1.6.2.min.js"></script>
    <script src="/js/public_ajax.js" type="text/javascript"></script>
    <link href="/css/common.css" rel="stylesheet" type="text/css" />
    <link href="/css/UserManager.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div class="pageTitle">
        <p><img src="/css/image/tubiao_28.png" />您的位置：<span>顾客列表</span></p>
    </div>

    <div class="queryConditionDiv">
        <div class="queryText">
            <span>姓名：</span>
            <input type="text" id="Name" class="textinput" />

            <span>电话：</span>
            <input type="text" id="Phone" class="textinput" />
        </div>

        <input id="btnSearch" type="button" value="" class="queryButton" />
        <script type="text/javascript">
            function searchgo() {
                var SortId = $("SortId").value;
                var BrandId = $("BrandId").value;
                var ProductName = $("ProductName").value;
                document.location.href = "ProductManager.aspx"
                                       + "?SortId=" + SortId
                                       + "&BrandId=" + BrandId
                                       + "&ProductName=" + ProductName;
            }
        </script>
    </div>

    <div class="List_head">
        <div class="head_left"></div>
        <div class="head_bj">
            <div class="xiangxi">顾客列表</div>
            <a class="xinZeng" href="Edit"></a>
        </div>
        <div class="head_right"></div>
    </div>

    <div class="list_table" id="divTabel">
        <table class="dataShowTable" id="tb">
            <tr>
                <th>姓名</th>
                <th>编号</th>
                <th>电话</th>
                <th></th>
            </tr>

        </table>

        <div id="BOX_overlay">
            <div id="ajaxinfo"></div>
        </div>
    </div>
    <div id="divHidden">
        <input type="hidden" id="strWhere" />
        <input type="hidden" id="pageIndex" value="1" />
    </div>
    <script type="text/javascript">
        $(function () {//页面加载完成执行
            getList("", 1);

            $("#btnSearch").click(search);
        });

        function removeAll(tableId) {//清除table已有的内容
            var tbody = document.getElementById(whichId).children[0];
            var all_children = tbody.children;
            while (all_children.length > 1) {
                tbody.removeChild(tbody.lastChild);
            }
        }

        function removeAll2(tableId) {//清除table已有的内容
            $("#" + tableId + " tr:not(:first)").remove();
        }

        function search() {
            var strWhere = "";
            var Name = $("#Name").val();
            var Phone = $("#Phone").val();
            if ($.trim(Name) != "")
                strWhere += " AND Name LIKE '%" + Name + "%'";
            if ($.trim(Phone) != "")
                strWhere += " AND Phone LIKE '%" + Phone + "%'";

            //var pageIndex = $("#pageIndex").val();
            getList(strWhere, 1);
        }

        function homePage() {
            turnPage(1);
        }

        function turnPage(pageIndex) {
            var strWhere = $("#strWhere").val();
            getList(strWhere, pageIndex);
        }

        function getList(strWhere, pageIndex) {
            $.ajax({
                url: '@Url.Action("GetCustomer")',
                data: { strWhere: strWhere, pageIndex: pageIndex },
                type: "POST",
                dataType: 'text',
                success: function (data) {
                    var pageTable = eval('(' + data + ')');
                    var TotalCount = pageTable.TotalCount;
                    var DataTable = pageTable.DataTable;
                    bb(DataTable);
                    MakePagination(pageTable);
                },
                error: function (xhr, textStatus, error) {
                    alert(error);
                }
            });
        }

        function bb(list) {
            removeAll2("tb");
            var table = $("#tb");
            for (var i = 0; i < list.length; i++) {
                var tr = $("<tr>");
                tr.attr('id', "tr" + list[i]["Id"]);

                tr.append($("<td class=''>" + format(list[i]["Name"]) + "</td>"));
                tr.append($("<td class=''>" + format(list[i]["SerialNumber"]) + "</td>"));
                tr.append($("<td class=''>" + format(list[i]["Phone"]) + "</td>"));

                tr.append($("<td class=''>"
                    + "<a href='Edit?Id=" + list[i]["Id"] + "'>修改</a>"
                    + "<a href='javascript:void(0)' onclick=\"del('OrganizationEdit.aspx' , " + list[i]["Id"] + ")\">删除</a>"
                    + "</td>"));
                table.append(tr);
            }
        }

        function format(value) {
            return value == null ? "" : value;
        }

        function MakePagination(pageTable) {
            var TotalCount = pageTable.TotalCount;//总记录数
            var PageSize = pageTable.PageSize;//每页记录数

            var HasPreviousPage = pageTable.HasPreviousPage;//是否有上一页
            var HasNextPage = pageTable.HasNextPage;//是否有下一页
            var PageIndex = pageTable.PageIndex;//当前页
            var TotalPages = pageTable.TotalPages;//总页数

            var strHomePagePreviousPage = "<a href='javascript:void(0)' onclick='homePage()'>首页</a>"
                                        + "<a href='javascript:void(0)' onclick='previousPage()'>"
                                            + "<img src='../css/image/tubiao_47.png' class='list-IMG' />"
                                        + "</a>";
            var strNextPageEndPage = "<a href='javascript:void(0)' onclick='nextPage()'>"
                                            + "<img src='../css/image/tubiao_50.png' class='list-IMG' />"
                                        + "</a>"
                                        + "<a href='javascript:void(0)' onclick='endPage()'>尾页</a>";
            strHomePagePreviousPage = HasPreviousPage ? strHomePagePreviousPage : "";
            strNextPageEndPage = HasNextPage ? strNextPageEndPage : "";

            var strPagination = "<div class='list-YeMa' id='divYeMa'>"
                                    + "<span class='JILU'>共 " + TotalCount + " 条记录，每页 " + PageSize + " 条</span>"
                                    + "<div class='TiaoZhuan'>"
                                        + strHomePagePreviousPage
                                        + "<span class='currentPageSpan'>" + PageIndex + "/" + TotalPages + "页</span>"
                                        + strNextPageEndPage
                                    + "</div>"
                                + "</div>";
            $("#divYeMa").remove();
            $("#divTabel").append($(strPagination));
        }
    </script>
</body>
</html>
